import random

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def generate_binary_tree(depth):
    if depth == 0:
        return None
    val = random.randint(1, 100)  # 随机生成节点的值
    left_depth = random.randint(0, depth - 1)  # 随机生成左子树的深度
    right_depth = depth - 1 - left_depth  # 计算右子树的深度
    return TreeNode(val, generate_binary_tree(left_depth), generate_binary_tree(right_depth))

def max_depth(root):
    if root is None:
        return 0
    left_depth = max_depth(root.left)
    right_depth = max_depth(root.right)
    return max(left_depth, right_depth) + 1

# 生成深度为 4 的随机二叉树
depth = 4
root = generate_binary_tree(depth)
print("随机生成的二叉树最大深度为:", max_depth(root))
